<!-- 页面外套 -->
<div class="page-wrapper" id="personnel_security_bill">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped">
        <!-- 工具条组 -->
        <div class="tool-group">
            <form class="tool-search">
                <input type="hidden" name='page'>
                <input type="hidden" name='recPerPage'>
                <div class="im-label">
                    <span>选择月份</span>
                    <div class="input-group">
                        <input type="text" class="form-control" name="starttime" readonly>
                    </div>
                </div>
                <br><br>
                <div class="clearfix"></div>
            </form>
            <div class="tool-deal">
                <label><button type="button" class="btn btn-primary tool_export_btn">生成账单</button></label>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->

    <!-- 生成盒子 -->
    <div class="modal modal-for-page fade tool_export_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">生成账单</h4>
                </div>
                <div class="modal-body">
                    <form class="container form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2">选择月份</label>
                            <div class="col-sm-8"><input type="text" class="form-control" name="month" readonly></div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary tool_export_submit">提交</button>
                </div>
            </div>
        </div>
    </div>

</div>
<!-- page-wrapper -->

<script>
$(function() {

    //变量声明
    var personnel_security_bill = $("#personnel_security_bill");
    var personnel_security_bill_api = {
        datagrid : API.test_datagrid,
        export : API.test_response,
    }

    //数据表格
    //数据源
    var personnel_security_bill_dataSource = {
        cols   : [
            {name: "name", label: "参保月份",width: 100},
            {name: "name", label: "参保人数",width: 90},
            {name: "text4",label: "个人社保费用",width: 120},
            {name: "text4",label: "公司社保费用",width: 120},
            {name: "text4",label: "个人公积金费用",width: 120},
            {name: "text4",label: "公司公积金费用",width: 120},
            {name: "text4",label: "服务费用",width: 90},
            {name: "text4",label: "合计费用",width: 90},
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : personnel_security_bill, 
                url      : personnel_security_bill_api.datagrid
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : personnel_security_bill,
                data     : data
            });
        }
    };
    //实例化
    personnel_security_bill.find('.datagrid').datagrid(
        zui_datagrid_option({
            datagrid   : personnel_security_bill.find('.datagrid'),
            dataSource : personnel_security_bill_dataSource
        })
    );
    //搜索
    personnel_security_bill.find('.tool-search [name="starttime"]').change(function(){ 
        zui_datagrid_render({
            datagrid_obj : personnel_security_bill.find('.datagrid').data("zui.datagrid"),
            dataSource   : personnel_security_bill_dataSource
        }); 
    });

    // 生成账单
    personnel_security_bill.on("click", ".tool_export_btn", function(){
        personnel_security_bill.find('.tool_export_box').modal('show');
    });
    personnel_security_bill.on("click", ".tool_export_submit", function(){
        $.ajax({
            url : personnel_security_bill_api.export,
            type: "post",
            dataType: "json",
            data : um_data_get( personnel_security_bill.find('.tool_export_box form') ),
            beforesend: function() {
                um_tip("导出中…");
            },
            success: function(data) {
                if (data.status > 0) {
                    window.open(API.test_export);
                    um_tip(data.message);
                    setTimeout(function(){
                        personnel_security_bill.find('.tool_export_box').modal('hide');
                    }, 1500);
                } else {
                    um_tip(data.message, "1500", "text-danger");
                }
            }
        });
    });

    // 组件实例化
    personnel_security_bill.find('.tool-search [name="starttime"]').datetimepicker(option_month);
    personnel_security_bill.find('.tool_export_box [name="month"]').datetimepicker(option_month);

}); //预加载结尾
</script>